package com.system.provider;

import com.am.ui.grid.AbstractBaseGridProvider;
import com.system.uitls.ChartUtils;
import com.system.uitls.CommonUtil;
import java.util.Map;

public class DoctorReportProvider extends AbstractBaseGridProvider
{
  public String generateSql(Map<String, Object> map)
  {
    String startDate = CommonUtil.nullToEmptyString(map.get("startDate"));
    String endDate = CommonUtil.nullToEmptyString(map.get("endDate"));
    String dateType = CommonUtil.nullToEmptyString(map.get("dateType"));
    String type = CommonUtil.nullToEmptyString(map.get("type"));

    startDate = ChartUtils.parseToComplete(startDate, dateType);
    endDate = ChartUtils.parseToComplete(endDate, dateType);

    ChartUtils chart = new ChartUtils();

    if ("1".equals(type)) {
      chart.setSql("SELECT user_name FROM sys_patient_record t1,sys_diagnose t2 where t1.create_time>=? and t1.create_time<=? AND status='7' AND t2.record_id=t1.id group by user_name");
    }
    else if ("2".equals(type))
    {
      chart.setSql("SELECT user_name FROM sys_patient_record t1,sys_diseaseLeave t2 where t1.create_time>=? and t1.create_time<=? AND status='7' AND t2.record_id=t1.id group by user_name");
    }
    else {
      chart.setSql("SELECT user_name FROM sys_patient_record t1,sys_referral t2 where t1.create_time>=? and t1.create_time<=? AND status='7' AND t2.record_id=t1.id group by user_name");
    }
    chart.setName("user_name");
    chart.setSum("sum(1)");

    setParamArray(new Object[] { startDate, endDate });
    return chart.generateSql("t1.create_time", startDate, endDate, dateType);
  }
}